function [ v ] = solver( A0, f ,m ,n)
%SOLVER Summary of this function goes here
%   Detailed explanation goes here

assert(length(f) == size(A0,1));
assert(length(f) == size(A0,2));

global A;
global P;
global dimm;
global D;
global iD;
global C;
global k;

[A,P,dimm, D, iD, C] = prepareAll(m, n, A0, k);

% v = fmg(f, 1);

v = zeros(size(f));

iters = 15;
resnorm = zeros(iters+1,1);
resnorm(1) = norm(f - A{1}*v);

for iter = 1:iters
    v = vcycle( v, f, 1);
    resnorm(iter+1) = norm(f - A{1}*v); 
end

figure(1)
semilogy(0:iters,resnorm,'ko-','markersize',8,'linewidth',5)
figure(2)
plot(1:iters,resnorm(2:end)./resnorm(1:end-1),'ko-','markersize',8,'linewidth',5)

